package com.ny.demo523;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class TestConnection {
    private static final String URL = " jdbc: mysql:// localhost:3306/usersDb";
    private static final String username = " root";
    private static final String password = "123456";

    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection(URL, username, password);

        String sql = " insert into users(username, password) values(?,?）";

        PreparedStatement pstm = conn.prepareStatement(sql);

        Scanner scanner = new Scanner(System.in);
        System.out.println();
        String username = scanner.next("请输入用户名");
        System.out.println();
        String password = scanner.next("请输入密码");
        pstm.setString(1, username);
        pstm.setString(2, password);
        int i = pstm.executeUpdate();
        if (i > 0) {
            System.out.println("请输入用户名");
        } else {
            System.out.println("请输入密码");
        }
    }
}